In time, you will call me master -- Star Wars
python import serial
)
COM_PORT = 'XXX'
BAUD_RATES = xxxxx
#initailize connection
ser = serial.Serial(COM_PORT, BAUD_RATES, stopbits = 1 )
while ser.in_waiting: # if receive data
# byte type raw data
data_raw = ser.read()
# byte to hex
data_hex = data_raw.hex()
start
: 0x01 , end
: 0x03 )byte stuffing
xor
0x10xor
回原本的把 1 去掉cluster
0x0400 : light level, cluster 0x0402 : temperaturedata
欄位 hex to int 我們可以知道 溫度, 亮度值dictionary
把 這些欄位 裝進去就好import firebase_admin
from firebase_admin import credentials
from firebase_admin import firestore
cred = credentials.Certificate('./ServiceAccountKey.json')
firebase_admin.initailize_app(cred)
db = firestore.client()
doc_ref = db.collection("database name")
# upload data to firestore
doc_ref.document(your key).set(your value)
Next blog post : flutter firestore + flutter chart